﻿using Common;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameRoot : MonoBehaviour
{
	#region 单例模型
	static GameRoot instance;
	private void Awake() { instance = this; }
	public static GameRoot Instance { get { return instance; } }

	#endregion


	public UIManager uiMng;
	public ClientManager clientMng;
	public ResponseManager responseMng;

	public ReceiveScreen screen;
	public GamePanel gamePanel1;
	public bool Online {
		get {
			return (uiMng.GetPanel(UIPanelType.ModePanel) as ModePanel).SelectOnline;
		}
	}

	void Start() {
		uiMng = new UIManager(this);
		clientMng = new ClientManager(this);
		responseMng = new ResponseManager(this);
		screen = GameObject.Find("Canvas").transform.Find("ReceiveScreen").GetComponent<ReceiveScreen>();
		gamePanel1 = GameObject.Find("ReceiveCanvas").transform.Find("GamePanel").GetComponent<GamePanel>();

		OnInit();
	}

	public void OnInit() {
		uiMng.OnInit();
		clientMng.OnInit();
		responseMng.OnInit();
	}



	public void HandleResponse(ActionCode actionCode, string data) {
		responseMng.HandleAction(actionCode, data);
	}

	public void AddAction(ActionCode actionCode, BaseRequest baseRequest) {
		responseMng.AddRequest(actionCode, baseRequest);
	}

	public void RemoveAction(ActionCode actionCode) {
		responseMng.RemoveRequest(actionCode);
	}

	public void SendRequest(RequestCode requestCode, ActionCode actionCode, string data) {
		clientMng.SendRequest(requestCode, actionCode, data);
	}




	public void ShowGrid2(int dif) {
		screen.OnOpen();
		gamePanel1.CreateGrid(dif);
	}

}
